
import os
import time
from os import getcwd
import numpy as np
import cv2
from PyQt5 import QtCore, QtGui, QtWidgets, Qt
from PyQt5.QtWidgets import QFileDialog, QMessageBox, QWidget
from PyQt5.QtCore import QThread, pyqtSignal, QPoint, QSize
import image1_rc
from Detector_Model import Detector
from sort import KalmanBoxTracker
from collections import deque
from PyQt5.QtGui import QMouseEvent
from speed import Car


class Ui_MainWindow(object):
    def __init__(self, MainWindow):

        self.path = getcwd()
        self.video_path = getcwd()
        self.model_path = "../yolo-obj/yolov4.weights"  # 模型默认路径
        self.timer_camera = QtCore.QTimer()  # 定时器
        self.timer_video = QtCore.QTimer()  # 视频定时器
        self.flag_timer = ""  # 用于标记正在进行的功能项（视频/摄像）

        self.setupUi(MainWindow)
        self.retranslateUi(MainWindow)
        self.slot_init()  # 槽函数设置

        self.radioButton_countting.setChecked(True)
        self.CAM_NUM = 0  # 摄像头标号
        self.cap = cv2.VideoCapture(self.CAM_NUM)  # 屏幕画面对象
        self.cap_video = None  # 视频流对象

        self.current_image = None  # 保存的画面
        self.detected_image = None
        # 画面的检测结果
        self.dets = []
        self.boxes = []
        self.indexIDs = []
        self.cls_IDs = []

        model_path = "../yolo-obj"  # 模型文件的目录
        labelsPath = os.path.sep.join([model_path, "coco.names"])
        self.LABELS = open(labelsPath).read().strip().split("\n")

        # 初始化用于标记框的颜色
        np.random.seed(42)
        self.COLORS = np.random.randint(0, 255, size=(200, 3), dtype="uint8")

        # 用于展示目标移动路径
        self.pts = [deque(maxlen=30) for _ in range(9999)]
        self.detector_model = Detector(self.model_path)

        # 用于表示选择的模式。1：图片；2：视频；3：摄像头
        self.type = 0

        self.textlineSty = "border-radius: 5px;border: 2px solid rgb(255, 255, 255);\n"+"background-color:rgba(255, 255, 255,0.3);font-family: '微软雅黑';\n"+"color: rgb(255, 255, 255);font-size:8pt;\n"

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowModality(QtCore.Qt.NonModal)
        MainWindow.resize(1728, 950)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(1728, 950))
        MainWindow.setMaximumSize(QtCore.QSize(1728, 950))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(-1)
        MainWindow.setFont(font)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/result.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setToolTip("")
        MainWindow.setAutoFillBackground(False)
        MainWindow.setStyleSheet("*{    \n"
                                 "    font-family:微软雅黑;\n"
                                 "    font-size:15px;\n"
                                 "    color: rgb(0, 0, 0);\n"
                                 "}\n"
                                 "\n"
                                 "#MainWindow{background-image:url(:/newPrefix/images_test/background1.png);}\n"
                                 "\n"
                                 "#button_min{border-image: url(:/newPrefix/images_test/min.png);width:45px;height:45px;background-color: transparent;}\n"
                                 "\n"
                                 "#button_max{border-image: url(:/newPrefix/images_test/max.png);width:45px;height:45px;background-color: transparent;}\n"
                                 "#button_close{border-image: url(:/newPrefix/images_test/close.png);width:45px;height:45px;background-color: transparent;}\n"
                                 "\n"
                                 "#comboBox{border-radius: 5px;\n"
                                 "border: 2px solid rgb(255, 255, 255);\n"
                                 "background-color:rgba(255, 255, 255,0.3);\n"
                                 "font-family: \"微软雅黑\";\n"
                                 "color: rgb(255, 255, 255);\n"
                                 "font-size: 8pt;}\n"
                                 "\n"
                                 "#VideoInput,#ModelChoose,#VolumeFrame,#CountFrame,#OccupFrame{\n"
                                 "  border-radius: 10px;\n"
                                 "  border: 2px solid rgb(126, 172, 213);\n"
                                 "  padding: 20px; \n"
                                 "  width: 200px;\n"
                                 "  height: 150px;\n"
                                 "background-color:rgba(110, 152, 190,0.2); \n"
                                 "}\n"
                                 "\n"
                                 ".QTextEdit{\n"
                                 "    border-radius: 5px;\n"
                                 "    border: 2px solid rgb(255, 255, 255);\n"
                                 "    font-family: Arial, Helvetica, sans-serif;\n"
                                 "padding: 6px; \n"
                                 "    background-color:rgba(255, 255, 255,0.3);\n"
                                 "    /*opacity: 0.1;*/\n"
                                 "    color: rgb(255, 255, 255);\n"
                                 "    font-size: 8pt;\n"
                                 "}\n"
                                 ".QLineEdit{\n"
                                 "    border-radius: 5px;\n"
                                 "    border: 2px solid rgb(255, 255, 255);\n"
                                 "    font-family: \"微软雅黑\";\n"
                                 "padding: 6px; \n"
                                 "    background-color:rgba(255, 255, 255,0.3);\n"
                                 "    /*opacity: 0.1;*/\n"
                                 "    color: rgb(255, 255, 255);\n"
                                 "    font-size: 8pt;\n"
                                 "}\n"
                                 "\n"
                                 "#listWidget{\n"
                                 "    border-radius: 5px;\n"
                                 "    border: 0.5px solid rgb(255, 255, 255);\n"
                                 "    font-family: \"微软雅黑\"; \n"
                                 "    background-color:rgba(255, 255, 255,0.3);\n"
                                 "    /*opacity: 0.1;*/\n"
                                 "    color: rgb(255, 255, 255);\n"
                                 "    font-size: 8pt;\n"
                                 "}\n"
                                 "\n"
                                 "#total_count,#car_count,#truck_count{\n"
                                 "    width:100px;\n"
                                 "    height:30px;\n"
                                 "}\n"
                                 "\n"
                                 ".QRadioButton{\n"
                                 "    font-family:\"微软雅黑\";\n"
                                 "    color: rgb(255, 255, 255);\n"
                                 "    font-size: 10pt;\n"
                                 "}\n"
                                 "\n"
                                 ".QLabel{\n"
                                 "font-family: \"微软雅黑\";\n"
                                 "color: rgb(225, 225, 225);\n"
                                 "font-size: 10pt;\n"
                                 "border:5px;\n"
                                 "}\n"
                                 ".QLabel::hover {\n"
                                 "border:0px;}\n"
                                 "\n"
                                 ".QFrame{border:5px;}\n"
                                 ".QFrame::hover {\n"
                                 "border:0px;}\n"
                                 "\n"
                                 "QFrame#line,#line_2,#line_6,#line_4,#line_7,#line_8,#line_9,#line_10{\n"
                                 "    color:rgb(255, 255, 255);\n"
                                 "}\n"
                                 "\n"
                                 "#label_2,#label_3,#label_4,#label_5{\n"
                                 "font: 11pt \"微软雅黑\";\n"
                                 "}\n"
                                 "\n"
                                 "\n"
                                 "QMenuBar{border-color:transparent;}\n"
                                 "QToolButton[objectName=pushButton_doIt]{\n"
                                 "border:5px;}\n"
                                 "\n"
                                 "QToolButton[objectName=pushButton_doIt]:hover {\n"
                                 "image:url(:/newPrefix/images_test/run_hover.png);}\n"
                                 "\n"
                                 "QToolButton[objectName=pushButton_doIt]:pressed {\n"
                                 "image:url(:/newPrefix/images_test/run_pressed.png);}\n"
                                 "\n"
                                 "QLable[objectName=lable_display]{border-image: url(:/newPrefix/images_test/car-night.jpg);}\n"
                                 "\n"
                                 "QScrollBar:vertical{\n"
                                 "background:transparent;\n"
                                 "padding:2px;\n"
                                 "border-radius:4px;\n"
                                 "max-width:8px;}\n"
                                 "\n"
                                 "QScrollBar::handle:vertical{\n"
                                 "background:#9acd32;\n"
                                 "min-height:8px;\n"
                                 "border-radius:4px;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::handle:vertical:hover{\n"
                                 "background:#9eb764;}\n"
                                 "\n"
                                 "QScrollBar::handle:vertical:pressed{\n"
                                 "background:#9eb764;\n"
                                 "}\n"
                                 "QScrollBar::add-page:vertical{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "                               \n"
                                 "QScrollBar::sub-page:vertical{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::add-line:vertical{\n"
                                 "background:none;}\n"
                                 "                                 \n"
                                 "QScrollBar::sub-line:vertical{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "QScrollArea{\n"
                                 "border:0px;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar:horizontal{\n"
                                 "background:transparent;\n"
                                 "padding:0px;\n"
                                 "border-radius:4px;\n"
                                 "max-height:6px;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::handle:horizontal{\n"
                                 "background:#9acd32;\n"
                                 "min-width:8px;\n"
                                 "border-radius:4px;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::handle:horizontal:hover{\n"
                                 "background:#9eb764;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::handle:horizontal:pressed{\n"
                                 "background:#9eb764;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::add-page:horizontal{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::sub-page:horizontal{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "QScrollBar::add-line:horizontal{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "\n"
                                 "QScrollBar::sub-line:horizontal{\n"
                                 "background:none;\n"
                                 "}\n"
                                 "QToolButton::hover{\n"
                                 "border:0px;\n"
                                 "} ")
        MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label_pic_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_pic_2.setGeometry(QtCore.QRect(1, 1, 161, 51))
        self.label_pic_2.setStyleSheet("border-image: url(:/newPrefix/images_test/menu.png);")
        self.label_pic_2.setText("")
        self.label_pic_2.setObjectName("label_pic_2")
        self.toolButton_saveing = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton_saveing.setGeometry(QtCore.QRect(11, 11, 31, 26))
        self.toolButton_saveing.setMaximumSize(QtCore.QSize(50, 45))
        self.toolButton_saveing.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_saveing.setAutoFillBackground(False)
        self.toolButton_saveing.setStyleSheet("background-color: transparent;\n"
                                              "border-color: rgb(0, 170, 255);\n"
                                              "color:rgb(0, 170, 255);")
        self.toolButton_saveing.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_saveing.setIcon(icon1)
        self.toolButton_saveing.setIconSize(QtCore.QSize(50, 39))
        self.toolButton_saveing.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_saveing.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_saveing.setAutoRaise(False)
        self.toolButton_saveing.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_saveing.setObjectName("toolButton_saveing")
        self.toolButton_version = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton_version.setGeometry(QtCore.QRect(118, 12, 31, 26))
        self.toolButton_version.setMaximumSize(QtCore.QSize(50, 45))
        self.toolButton_version.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_version.setAutoFillBackground(False)
        self.toolButton_version.setStyleSheet("background-color: transparent;\n"
                                              "border-color: rgb(0, 170, 255);\n"
                                              "color:rgb(0, 170, 255);")
        self.toolButton_version.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/versions.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_version.setIcon(icon2)
        self.toolButton_version.setIconSize(QtCore.QSize(50, 39))
        self.toolButton_version.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_version.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_version.setAutoRaise(False)
        self.toolButton_version.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_version.setObjectName("toolButton_version")
        self.toolButton_author = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton_author.setGeometry(QtCore.QRect(81, 11, 31, 26))
        self.toolButton_author.setMaximumSize(QtCore.QSize(50, 45))
        self.toolButton_author.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_author.setAutoFillBackground(False)
        self.toolButton_author.setStyleSheet("background-color: transparent;\n"
                                             "border-color: rgb(0, 170, 255);\n"
                                             "color:rgb(0, 170, 255);")
        self.toolButton_author.setText("")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/author.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_author.setIcon(icon3)
        self.toolButton_author.setIconSize(QtCore.QSize(50, 39))
        self.toolButton_author.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_author.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_author.setAutoRaise(False)
        self.toolButton_author.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_author.setObjectName("toolButton_author")
        self.toolButton_settings = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton_settings.setGeometry(QtCore.QRect(40, 8, 41, 31))
        self.toolButton_settings.setMaximumSize(QtCore.QSize(50, 45))
        self.toolButton_settings.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_settings.setAutoFillBackground(False)
        self.toolButton_settings.setStyleSheet("background-color: transparent;\n"
                                               "border-color: rgb(0, 170, 255);\n"
                                               "color:rgb(0, 170, 255);")
        self.toolButton_settings.setText("")
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/settings.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_settings.setIcon(icon4)
        self.toolButton_settings.setIconSize(QtCore.QSize(50, 39))
        self.toolButton_settings.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_settings.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_settings.setAutoRaise(False)
        self.toolButton_settings.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_settings.setObjectName("toolButton_settings")
        self.label_pic_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_pic_3.setGeometry(QtCore.QRect(1560, 0, 161, 51))
        self.label_pic_3.setStyleSheet("border-image: url(:/newPrefix/images_test/menu.png);")
        self.label_pic_3.setText("")
        self.label_pic_3.setObjectName("label_pic_3")
        self.button_close = QtWidgets.QPushButton(self.centralwidget)
        self.button_close.setGeometry(QtCore.QRect(1680, 10, 32, 32))
        self.button_close.setStyleSheet("background-color: transparent;\n"
                                        "border-color: rgb(0, 170, 255);\n"
                                        "color:rgb(0, 170, 255);")
        self.button_close.setText("")
        self.button_close.setObjectName("button_close")
        self.button_max = QtWidgets.QPushButton(self.centralwidget)
        self.button_max.setGeometry(QtCore.QRect(1630, 10, 32, 32))
        self.button_max.setText("")
        self.button_max.setObjectName("button_max")
        self.button_min = QtWidgets.QPushButton(self.centralwidget)
        self.button_min.setGeometry(QtCore.QRect(1580, 10, 32, 32))
        self.button_min.setText("")
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/min.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.button_min.setIcon(icon5)
        self.button_min.setIconSize(QtCore.QSize(32, 32))
        self.button_min.setObjectName("button_min")
        self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.layoutWidget.setGeometry(QtCore.QRect(0, 50, 1721, 121))
        self.layoutWidget.setObjectName("layoutWidget")
        self.horizontalLayout_17 = QtWidgets.QHBoxLayout(self.layoutWidget)
        self.horizontalLayout_17.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_17.setObjectName("horizontalLayout_17")
        spacerItem = QtWidgets.QSpacerItem(550, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_17.addItem(spacerItem)
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.label_title = QtWidgets.QLabel(self.layoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_title.sizePolicy().hasHeightForWidth())
        self.label_title.setSizePolicy(sizePolicy)
        self.label_title.setMinimumSize(QtCore.QSize(0, 30))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(26)
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        self.label_title.setFont(font)
        self.label_title.setStyleSheet("color:rgb(255, 255, 255);\n"
                                       "font: bold 26pt \"微软雅黑\";")
        self.label_title.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
        self.label_title.setObjectName("label_title")
        self.verticalLayout_3.addWidget(self.label_title)
        self.label = QtWidgets.QLabel(self.layoutWidget)
        self.label.setStyleSheet("color:rgb(255, 255, 255);\n"
                                 "font: 12pt \"微软雅黑\";")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout_3.addWidget(self.label)
        self.horizontalLayout_17.addLayout(self.verticalLayout_3)
        spacerItem1 = QtWidgets.QSpacerItem(550, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_17.addItem(spacerItem1)
        self.label_display = QtWidgets.QLabel(self.centralwidget)
        self.label_display.setGeometry(QtCore.QRect(340, 250, 1152, 648))
        self.label_display.setMinimumSize(QtCore.QSize(1152, 648))
        self.label_display.setMaximumSize(QtCore.QSize(1152, 648))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.label_display.setFont(font)
        self.label_display.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")
        self.label_display.setAlignment(QtCore.Qt.AlignCenter)
        self.label_display.setObjectName("label_display")
        self.VolumeFrame = QtWidgets.QFrame(self.centralwidget)
        self.VolumeFrame.setGeometry(QtCore.QRect(1499, 498, 221, 181))
        self.VolumeFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.VolumeFrame.setFrameShadow(QtWidgets.QFrame.Plain)
        self.VolumeFrame.setObjectName("VolumeFrame")
        self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.VolumeFrame)
        self.verticalLayout_5.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint)
        self.verticalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_5.setSpacing(5)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.horizontalLayout_13 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_13.setObjectName("horizontalLayout_13")
        self.label_2 = QtWidgets.QLabel(self.VolumeFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(11)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_2.setFont(font)
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_13.addWidget(self.label_2)
        self.verticalLayout_5.addLayout(self.horizontalLayout_13)
        spacerItem2 = QtWidgets.QSpacerItem(20, 71, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout_5.addItem(spacerItem2)
        self.horizontalLayout_11 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_11.setObjectName("horizontalLayout_11")
        self.label_useTime_4 = QtWidgets.QLabel(self.VolumeFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_useTime_4.setFont(font)
        self.label_useTime_4.setStyleSheet("")
        self.label_useTime_4.setObjectName("label_useTime_4")
        self.horizontalLayout_11.addWidget(self.label_useTime_4)
        self.volume1 = QtWidgets.QLineEdit(self.VolumeFrame)
        self.volume1.setMinimumSize(QtCore.QSize(100, 45))
        self.volume1.setMaximumSize(QtCore.QSize(100, 45))
        self.volume1.setText("")
        self.volume1.setReadOnly(True)
        self.volume1.setObjectName("volume1")
        self.horizontalLayout_11.addWidget(self.volume1)
        self.verticalLayout_5.addLayout(self.horizontalLayout_11)
        self.horizontalLayout_12 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_12.setObjectName("horizontalLayout_12")
        self.label_useTime_5 = QtWidgets.QLabel(self.VolumeFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_useTime_5.setFont(font)
        self.label_useTime_5.setStyleSheet("")
        self.label_useTime_5.setObjectName("label_useTime_5")
        self.horizontalLayout_12.addWidget(self.label_useTime_5)
        self.volume2 = QtWidgets.QLineEdit(self.VolumeFrame)
        self.volume2.setMinimumSize(QtCore.QSize(100, 45))
        self.volume2.setMaximumSize(QtCore.QSize(100, 45))
        self.volume2.setText("")
        self.volume2.setReadOnly(True)
        self.volume2.setObjectName("volume2")
        self.horizontalLayout_12.addWidget(self.volume2)
        self.verticalLayout_5.addLayout(self.horizontalLayout_12)
        self.verticalLayout_5.setStretch(1, 2)
        self.verticalLayout_5.setStretch(2, 1)
        self.verticalLayout_5.setStretch(3, 1)
        self.OccupFrame = QtWidgets.QFrame(self.centralwidget)
        self.OccupFrame.setGeometry(QtCore.QRect(1499, 708, 221, 181))
        self.OccupFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.OccupFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.OccupFrame.setObjectName("OccupFrame")
        self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.OccupFrame)
        self.verticalLayout_6.setContentsMargins(0, 2, 0, 2)
        self.verticalLayout_6.setSpacing(5)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        self.horizontalLayout_14 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_14.setObjectName("horizontalLayout_14")
        self.label_4 = QtWidgets.QLabel(self.OccupFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(11)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_4.setFont(font)
        self.label_4.setAlignment(QtCore.Qt.AlignCenter)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_14.addWidget(self.label_4)
        self.verticalLayout_6.addLayout(self.horizontalLayout_14)
        spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout_6.addItem(spacerItem3)
        self.horizontalLayout_15 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_15.setObjectName("horizontalLayout_15")
        self.label_useTime_6 = QtWidgets.QLabel(self.OccupFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_useTime_6.setFont(font)
        self.label_useTime_6.setStyleSheet("")
        self.label_useTime_6.setObjectName("label_useTime_6")
        self.horizontalLayout_15.addWidget(self.label_useTime_6)
        self.density1 = QtWidgets.QLineEdit(self.OccupFrame)
        self.density1.setMinimumSize(QtCore.QSize(100, 45))
        self.density1.setMaximumSize(QtCore.QSize(100, 45))
        self.density1.setText("")
        self.density1.setReadOnly(True)
        self.density1.setObjectName("density1")
        self.horizontalLayout_15.addWidget(self.density1)
        self.verticalLayout_6.addLayout(self.horizontalLayout_15)
        self.horizontalLayout_16 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_16.setObjectName("horizontalLayout_16")
        self.label_useTime_7 = QtWidgets.QLabel(self.OccupFrame)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_useTime_7.setFont(font)
        self.label_useTime_7.setStyleSheet("")
        self.label_useTime_7.setObjectName("label_useTime_7")
        self.horizontalLayout_16.addWidget(self.label_useTime_7)
        self.density2 = QtWidgets.QLineEdit(self.OccupFrame)
        self.density2.setMinimumSize(QtCore.QSize(100, 45))
        self.density2.setMaximumSize(QtCore.QSize(100, 45))
        self.density2.setText("")
        self.density2.setReadOnly(True)
        self.density2.setObjectName("density2")
        self.horizontalLayout_16.addWidget(self.density2)
        self.verticalLayout_6.addLayout(self.horizontalLayout_16)
        self.verticalLayout_6.setStretch(2, 1)
        self.verticalLayout_6.setStretch(3, 1)
        self.VideoInput = QtWidgets.QFrame(self.centralwidget)
        self.VideoInput.setGeometry(QtCore.QRect(10, 280, 321, 271))
        self.VideoInput.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.VideoInput.setFrameShadow(QtWidgets.QFrame.Raised)
        self.VideoInput.setObjectName("VideoInput")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.VideoInput)
        self.verticalLayout.setContentsMargins(0, 2, 0, 2)
        self.verticalLayout.setSpacing(5)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.toolButton_model = QtWidgets.QToolButton(self.VideoInput)
        self.toolButton_model.setMinimumSize(QtCore.QSize(0, 0))
        self.toolButton_model.setMaximumSize(QtCore.QSize(50, 40))
        self.toolButton_model.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_model.setAutoFillBackground(False)
        self.toolButton_model.setStyleSheet("background-color: transparent;")
        self.toolButton_model.setText("")
        icon6 = QtGui.QIcon()
        icon6.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/folder_web.png"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.toolButton_model.setIcon(icon6)
        self.toolButton_model.setIconSize(QtCore.QSize(50, 40))
        self.toolButton_model.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_model.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_model.setAutoRaise(False)
        self.toolButton_model.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_model.setObjectName("toolButton_model")
        self.horizontalLayout.addWidget(self.toolButton_model)
        self.comboBox = QtWidgets.QComboBox(self.VideoInput)
        self.comboBox.setMinimumSize(QtCore.QSize(180, 45))
        self.comboBox.setMaximumSize(QtCore.QSize(100, 45))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.toolButton_camera = QtWidgets.QToolButton(self.VideoInput)
        self.toolButton_camera.setMinimumSize(QtCore.QSize(50, 39))
        self.toolButton_camera.setMaximumSize(QtCore.QSize(50, 45))
        self.toolButton_camera.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_camera.setAutoFillBackground(False)
        self.toolButton_camera.setStyleSheet("background-color: transparent;\n"
                                             "border-color: rgb(0, 170, 255);\n"
                                             "color:rgb(0, 170, 255);")
        self.toolButton_camera.setText("")
        icon7 = QtGui.QIcon()
        icon7.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/g1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_camera.setIcon(icon7)
        self.toolButton_camera.setIconSize(QtCore.QSize(50, 39))
        self.toolButton_camera.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_camera.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_camera.setAutoRaise(False)
        self.toolButton_camera.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_camera.setObjectName("toolButton_camera")
        self.horizontalLayout_2.addWidget(self.toolButton_camera)
        self.textEdit_camera = QtWidgets.QLineEdit(self.VideoInput)
        self.textEdit_camera.setMinimumSize(QtCore.QSize(180, 45))
        self.textEdit_camera.setMaximumSize(QtCore.QSize(100, 45))
        self.textEdit_camera.setReadOnly(True)
        self.textEdit_camera.setObjectName("textEdit_camera")
        self.horizontalLayout_2.addWidget(self.textEdit_camera)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.toolButton_file = QtWidgets.QToolButton(self.VideoInput)
        self.toolButton_file.setMinimumSize(QtCore.QSize(50, 39))
        self.toolButton_file.setMaximumSize(QtCore.QSize(50, 40))
        self.toolButton_file.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_file.setAutoFillBackground(False)
        self.toolButton_file.setStyleSheet("background-color: transparent;")
        self.toolButton_file.setText("")
        icon8 = QtGui.QIcon()
        icon8.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/recovery.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_file.setIcon(icon8)
        self.toolButton_file.setIconSize(QtCore.QSize(50, 40))
        self.toolButton_file.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_file.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_file.setAutoRaise(False)
        self.toolButton_file.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_file.setObjectName("toolButton_file")
        self.horizontalLayout_3.addWidget(self.toolButton_file)
        self.textEdit_pic = QtWidgets.QLineEdit(self.VideoInput)
        self.textEdit_pic.setMinimumSize(QtCore.QSize(180, 45))
        self.textEdit_pic.setMaximumSize(QtCore.QSize(100, 45))
        self.textEdit_pic.setReadOnly(True)
        self.textEdit_pic.setObjectName("textEdit_pic")
        self.horizontalLayout_3.addWidget(self.textEdit_pic)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.toolButton_video = QtWidgets.QToolButton(self.VideoInput)
        self.toolButton_video.setMinimumSize(QtCore.QSize(50, 39))
        self.toolButton_video.setMaximumSize(QtCore.QSize(50, 40))
        self.toolButton_video.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toolButton_video.setAutoFillBackground(False)
        self.toolButton_video.setStyleSheet("background-color: transparent;")
        self.toolButton_video.setText("")
        icon9 = QtGui.QIcon()
        icon9.addPixmap(QtGui.QPixmap(":/newPrefix/images_test/video.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton_video.setIcon(icon9)
        self.toolButton_video.setIconSize(QtCore.QSize(33, 33))
        self.toolButton_video.setPopupMode(QtWidgets.QToolButton.DelayedPopup)
        self.toolButton_video.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.toolButton_video.setAutoRaise(False)
        self.toolButton_video.setArrowType(QtCore.Qt.NoArrow)
        self.toolButton_video.setObjectName("toolButton_video")
        self.horizontalLayout_4.addWidget(self.toolButton_video)
        self.textEdit_video = QtWidgets.QLineEdit(self.VideoInput)
        self.textEdit_video.setMinimumSize(QtCore.QSize(180, 45))
        self.textEdit_video.setMaximumSize(QtCore.QSize(100, 45))
        self.textEdit_video.setReadOnly(True)
        self.textEdit_video.setObjectName("textEdit_video")
        self.horizontalLayout_4.addWidget(self.textEdit_video)
        self.verticalLayout.addLayout(self.horizontalLayout_4)
        self.ModelChoose = QtWidgets.QFrame(self.centralwidget)
        self.ModelChoose.setGeometry(QtCore.QRect(10, 650, 311, 221))
        self.ModelChoose.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.ModelChoose.setFrameShadow(QtWidgets.QFrame.Raised)
        self.ModelChoose.setObjectName("ModelChoose")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.ModelChoose)
        self.verticalLayout_2.setContentsMargins(0, 2, 0, 2)
        self.verticalLayout_2.setSpacing(2)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.radioButton_detection = QtWidgets.QRadioButton(self.ModelChoose)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        self.radioButton_detection.setFont(font)
        self.radioButton_detection.setStyleSheet("")
        self.radioButton_detection.setObjectName("radioButton_detection")
        self.horizontalLayout_5.addWidget(self.radioButton_detection)
        self.label_pic_detection = QtWidgets.QLabel(self.ModelChoose)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_pic_detection.sizePolicy().hasHeightForWidth())
        self.label_pic_detection.setSizePolicy(sizePolicy)
        self.label_pic_detection.setMinimumSize(QtCore.QSize(40, 40))
        self.label_pic_detection.setMaximumSize(QtCore.QSize(40, 40))
        self.label_pic_detection.setStyleSheet("border-image: url(:/newPrefix/images_test/Cute_Vehicle.png);")
        self.label_pic_detection.setText("")
        self.label_pic_detection.setObjectName("label_pic_detection")
        self.horizontalLayout_5.addWidget(self.label_pic_detection)
        self.verticalLayout_2.addLayout(self.horizontalLayout_5)
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.radioButton_tracking = QtWidgets.QRadioButton(self.ModelChoose)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.radioButton_tracking.setFont(font)
        self.radioButton_tracking.setStyleSheet("")
        self.radioButton_tracking.setObjectName("radioButton_tracking")
        self.horizontalLayout_6.addWidget(self.radioButton_tracking)
        self.label_pic_tracking = QtWidgets.QLabel(self.ModelChoose)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_pic_tracking.sizePolicy().hasHeightForWidth())
        self.label_pic_tracking.setSizePolicy(sizePolicy)
        self.label_pic_tracking.setMinimumSize(QtCore.QSize(40, 40))
        self.label_pic_tracking.setMaximumSize(QtCore.QSize(40, 40))
        self.label_pic_tracking.setStyleSheet("border-image: url(:/newPrefix/images_test/tracking.png);\n"
                                              "border:5px;\n"
                                              "hover:{boder:0px;}")
        self.label_pic_tracking.setText("")
        self.label_pic_tracking.setObjectName("label_pic_tracking")
        self.horizontalLayout_6.addWidget(self.label_pic_tracking)
        self.verticalLayout_2.addLayout(self.horizontalLayout_6)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.radioButton_countting = QtWidgets.QRadioButton(self.ModelChoose)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.radioButton_countting.setFont(font)
        self.radioButton_countting.setStyleSheet("")
        self.radioButton_countting.setObjectName("radioButton_countting")
        self.horizontalLayout_7.addWidget(self.radioButton_countting)
        self.label_pic_coutting = QtWidgets.QLabel(self.ModelChoose)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_pic_coutting.sizePolicy().hasHeightForWidth())
        self.label_pic_coutting.setSizePolicy(sizePolicy)
        self.label_pic_coutting.setMinimumSize(QtCore.QSize(40, 40))
        self.label_pic_coutting.setMaximumSize(QtCore.QSize(40, 40))
        self.label_pic_coutting.setSizeIncrement(QtCore.QSize(40, 40))
        self.label_pic_coutting.setStyleSheet("border-image: url(:/newPrefix/images_test/tally.png);")
        self.label_pic_coutting.setText("")
        self.label_pic_coutting.setObjectName("label_pic_coutting")
        self.horizontalLayout_7.addWidget(self.label_pic_coutting)
        self.verticalLayout_2.addLayout(self.horizontalLayout_7)
        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(1500, 230, 221, 247))
        self.widget.setObjectName("widget")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.widget)
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.label_useTime = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(10)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_useTime.setFont(font)
        self.label_useTime.setStyleSheet("")
        self.label_useTime.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
        self.label_useTime.setObjectName("label_useTime")
        self.horizontalLayout_8.addWidget(self.label_useTime)
        self.total_count = QtWidgets.QLineEdit(self.widget)
        self.total_count.setMinimumSize(QtCore.QSize(100, 45))
        self.total_count.setMaximumSize(QtCore.QSize(100, 45))
        self.total_count.setText("")
        self.total_count.setReadOnly(True)
        self.total_count.setObjectName("total_count")
        self.horizontalLayout_8.addWidget(self.total_count)
        self.verticalLayout_4.addLayout(self.horizontalLayout_8)
        self.listWidget = QtWidgets.QListWidget(self.widget)
        self.listWidget.setObjectName("listWidget")
        self.verticalLayout_4.addWidget(self.listWidget)
        self.label_display.raise_()
        self.VolumeFrame.raise_()
        self.OccupFrame.raise_()
        self.VideoInput.raise_()
        self.ModelChoose.raise_()
        self.label_pic_2.raise_()
        self.layoutWidget.raise_()
        self.toolButton_saveing.raise_()
        self.toolButton_version.raise_()
        self.toolButton_author.raise_()
        self.toolButton_settings.raise_()
        self.label_pic_3.raise_()
        self.button_close.raise_()
        self.button_max.raise_()
        self.button_min.raise_()
        self.layoutWidget.raise_()
        self.listWidget.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.actionGoogle_Translate = QtWidgets.QAction(MainWindow)
        self.actionGoogle_Translate.setObjectName("actionGoogle_Translate")
        self.actionHTML_type = QtWidgets.QAction(MainWindow)
        self.actionHTML_type.setObjectName("actionHTML_type")
        self.actionsoftware_version = QtWidgets.QAction(MainWindow)
        self.actionsoftware_version.setObjectName("actionsoftware_version")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "车辆检测与交通流参数计算"))
            self.label_title.setToolTip(_translate("MainWindow", "<html><head/><body><p><br/></p></body></html>"))
            self.label_title.setText(_translate("MainWindow", "车辆检测与交通流参数计算"))
            self.label.setText(_translate("MainWindow", "智能运输检测技术综合设计"))
            self.label_display.setText(
                _translate("MainWindow", "<html><head/><body><p align=\"center\"><br/></p></body></html>"))
            self.label_2.setText(_translate("MainWindow", "车流量"))
            self.label_useTime_4.setText(_translate("MainWindow", "<html><head/><body><p>车道1：</p></body></html>"))
            self.label_useTime_5.setText(_translate("MainWindow", "<html><head/><body><p>车道2：</p></body></html>"))
            self.label_4.setText(_translate("MainWindow", "占有率"))
            self.label_useTime_6.setText(_translate("MainWindow", "<html><head/><body><p>车道1：</p></body></html>"))
            self.label_useTime_7.setText(_translate("MainWindow", "<html><head/><body><p>车道2：</p></body></html>"))
            self.comboBox.setItemText(0, _translate("MainWindow", "opencv"))
            self.comboBox.setItemText(1, _translate("MainWindow", "使用预训练好的模型"))
            self.textEdit_camera.setText(_translate("MainWindow", "实时摄像未开启"))
            self.textEdit_pic.setText(_translate("MainWindow", "选择图片文件"))
            self.textEdit_video.setText(_translate("MainWindow", "选择视频文件"))
            self.radioButton_detection.setText(_translate("MainWindow", "目标检测"))
            self.radioButton_tracking.setText(_translate("MainWindow", "目标跟踪"))
            self.radioButton_countting.setText(_translate("MainWindow", "跟踪计数"))
            self.label_useTime.setText(_translate("MainWindow", "<html><head/><body><p>Count:</p></body></html>"))
            self.actionGoogle_Translate.setText(_translate("MainWindow", "Google Translate"))
            self.actionHTML_type.setText(_translate("MainWindow", "HTML type"))
            self.actionsoftware_version.setText(_translate("MainWindow", "software version"))

    def slot_init(self):  # 定义槽函数
        self.toolButton_file.clicked.connect(self.choose_file)
        self.toolButton_camera.clicked.connect(self.button_open_camera_click)
        self.toolButton_video.clicked.connect(self.button_open_video_click)
        self.toolButton_saveing.clicked.connect(self.save_file)
        self.toolButton_settings.clicked.connect(self.setting)
        self.toolButton_author.clicked.connect(self.disp_mail)
        self.toolButton_version.clicked.connect(self.disp_version)
        self.timer_camera.timeout.connect(self.show_camera)
        self.timer_video.timeout.connect(self.show_video)
        self.button_close.clicked.connect(self.queryExit)
        self.comboBox.currentIndexChanged.connect(self.choose_model)

    def queryExit(self):
        exit()

    def pause_run(self):
        if self.flag_timer == "video":
            self.timer_video.stop()
        elif self.flag_timer == "camera":
            self.timer_camera.stop()

    def choose_model(self):
        if self.comboBox.currentText() == "使用预训练好的模型":
            # print("success")
            self.type = 4
            # 选择模型按钮点击事件的槽函数
            self.timer_camera.stop()  # 停止摄像计时器
            self.timer_video.stop()  # 停止视频计时器
            # 清空参数显示
            self.listWidget.clear()
            self.total_count.clear()
            self.volume1.clear()
            self.volume2.clear()
            self.density1.clear()
            self.density2.clear()
            if self.cap:
                self.cap.release()  # 释放画面帧
            if self.cap_video:
                self.cap_video.release()  # 释放视频画面帧
            # self.restore()
            self.flag_timer = ""

            # 调用文件选择对话框
            fileName_choose, filetype = QFileDialog.getOpenFileName(self.centralwidget,
                                                                    "选取权重文件", getcwd(),  # 起始路径
                                                                    "Model File (*.weights)")  # 文件类型
            # 显示提示信息
            if fileName_choose != '':
                self.model_path = fileName_choose
            else:
                self.model_path = "../yolo-obj/yolov4-tiny.weights"  # 模型默认路径

            # 默认CV检测

    def choose_file(self):
        # 选择图片或视频文件后执行此槽函数
        self.type = 1
        self.pts = [deque(maxlen=30) for _ in range(9999)]
        self.timer_camera.stop()
        self.timer_video.stop()
        # 清空参数显示
        self.listWidget.clear()
        self.total_count.clear()
        self.volume1.clear()
        self.volume2.clear()
        self.density1.clear()
        self.density2.clear()
        if self.cap:
            self.cap.release()
        if self.cap_video:
            self.cap_video.release()  # 释放视频画面帧
        # 使用文件选择对话框选择图片
        self.restore()
        self.flag_timer = ""
        fileName_choose, filetype = QFileDialog.getOpenFileName(
            self.centralwidget, "选取图片文件",
            self.path,  # 起始路径
            "图片(*.jpg;*.jpeg;*.png)")  # 文件类型
        self.path = fileName_choose  # 保存路径
        if fileName_choose != '':
            self.flag_timer = "image"
            self.textEdit_pic.setText(fileName_choose + '文件已选中')
            self.textEdit_pic.setStyleSheet(self.textlineSty)
            self.label_display.setText('正在启动识别系统...\n\nleading')
            QtWidgets.QApplication.processEvents()
            # 生成模型对象

            image = self.cv_imread(fileName_choose)  # 读取选择的图片
            self.current_image = image.copy()

            # 初始化检测模型对象
            detector_model = Detector(model_path=self.model_path)
            KalmanBoxTracker.count = 0
            time_start = time.time()
            self.dets, self.boxes, self.indexIDs, self.cls_IDs = detector_model.run(image)  # 执行检测跟踪
            time_end = time.time()

            # 在UI界面上显示检测结果
            ind_select = 0
            # ind = -1
            if len(self.dets) > 0:
                if len(self.LABELS[int(self.dets[ind_select][5])]) > 7:
                    font = QtGui.QFont()
                    font.setPointSize(12)
                else:
                    font = QtGui.QFont()
                    font.setPointSize(18)
            else:
                font = QtGui.QFont()
                font.setPointSize(18)

            if len(self.boxes) > 0:
                self.sign_up(image, 0)
                QtWidgets.QApplication.processEvents()
            else:
                # 更新检测目标数目
                a = 1

            self.detected_image = image.copy()
            # 在Qt界面中显示检测完成画面
            self.show_img(image)

        else:
            # 选择取消，恢复界面状态
            self.flag_timer = ""
            self.textEdit_pic.setText('文件未选中')
            self.textEdit_pic.setStyleSheet(self.textlineSty)
            self.label_display.clear()  # 清除画面
            self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")

    def button_open_camera_click(self):
        self.type = 3
        if self.timer_video.isActive():
            self.timer_video.stop()
        if not self.timer_camera.isActive():  # 检查定时状态
            flag = self.cap.open(self.CAM_NUM)  # 检查相机状态
            if not flag:  # 相机打开失败提示
                msg = QtWidgets.QMessageBox.warning(self.centralwidget, u"Warning",
                                                    u"请检测相机与电脑是否连接正确！ ",
                                                    buttons=QtWidgets.QMessageBox.Ok,
                                                    defaultButton=QtWidgets.QMessageBox.Ok)
                self.flag_timer = ""
            else:
                # 准备运行识别程序
                self.flag_timer = "camera"
                self.textEdit_pic.setText('文件未选中')
                self.textEdit_pic.setStyleSheet(self.textlineSty)
                self.textEdit_video.setText('实时视频已关闭')
                self.textEdit_video.setStyleSheet(self.textlineSty)
                QtWidgets.QApplication.processEvents()
                self.textEdit_camera.setText('实时摄像已启动')
                self.textEdit_camera.setStyleSheet(self.textlineSty)
                self.label_display.setText('正在启动识别系统...\n\nleading')
                # 新建对象
                self.pts = [deque(maxlen=30) for _ in range(9999)]
                self.detector_model = Detector(model_path=self.model_path)
                KalmanBoxTracker.count = 0
                self.restore()
                # 打开定时器
                self.timer_camera.start(30)
        else:
            # 定时器未开启，界面回复初始状态
            self.flag_timer = ""
            self.timer_camera.stop()
            if self.cap:
                self.cap.release()
            self.label_display.clear()
            self.textEdit_pic.setText('文件未选中')
            self.textEdit_pic.setStyleSheet(self.textlineSty)
            self.textEdit_camera.setText('实时摄像已关闭')
            self.textEdit_camera.setStyleSheet(self.textlineSty)
            self.textEdit_video.setText('实时视频已关闭')
            self.textEdit_video.setStyleSheet(self.textlineSty)

            self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")
            self.restore()

    def show_video(self):
        # 定时器槽函数，每隔一段时间执行
        flag, image = self.cap_video.read()  # 获取画面
        self.current_image = image.copy()
        if flag:
            if self.comboBox.currentText() == "使用预训练好的模型":

                self.dets, self.boxes, self.indexIDs, self.cls_IDs = self.detector_model.run(self.current_image)
                det_cars = []
                detslist = self.dets.tolist()
                for item in detslist:
                    if item[5] == 2 or item[5] == 7:
                        det_cars.append(item[0:4])

                if len(self.boxes) > 0:
                    i = int(0)
                    for box in self.boxes:  # 遍历所有标记框
                        (x, y) = (int(box[0]), int(box[1]))
                        (w, h) = (int(box[2]), int(box[3]))

                        color = [int(c) for c in self.COLORS[self.indexIDs[i] % len(self.COLORS)]]
                        cv2.rectangle(self.current_image, (x, y), (w, h), color, 4)
                        center = (int(((box[0]) + (box[2])) / 2), int(((box[1]) + (box[3])) / 2))
                        # 显示某个对象标记框的中心
                        thickness = 5
                        cv2.circle(self.current_image, center, 1, color, thickness)
                        # 标记跟踪到的目标和数目
                        text = "{}-{}".format(self.LABELS[int(self.cls_IDs[i])], self.indexIDs[i])
                        cv2.putText(self.current_image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, color, 3)
                        i += 1

                cv2.line(self.current_image, (self.left_bound1, self.line_height1), (self.right_bound1, self.line_height1), (255, 255, 255), 2)
                cv2.line(self.current_image, (self.left_bound2, self.line_height2), (self.right_bound2, self.line_height2), (255, 255, 255), 2)
                cv2.line(self.current_image, (0, self.line_height1), (self.frame_width, self.line_height1), (255, 255, 0), 1)
                cv2.line(self.current_image, (0, self.line_height2), (self.frame_width, self.line_height2), (255, 255, 0), 1)
                # 参数赋值
                null = True  # 如果这一帧没有检测到任何车，则将cars置空，减小误差,设置初始变量null设为True
                for item in self.dets:
                    (x, y, w, h) = int(item[0]), int(item[1]), int(item[2] - item[0]), int(
                        item[3] - item[1])  # dets:[x, y, x + w, y + h]
                    # 计算大轮廓的中心点,也就是矩形框的中心点，并把中心点都放到cars里面
                    cx = int(x + w / 2)
                    cy = int(y + h / 2)

                    if self.line_height2 - 30 < int(y + (h / 2)) < self.line_height1 + 30 and self.left_bound1 < int(
                            x + (w / 2)) < self.right_bound2:
                        null = False  # 有车时不会清空
                        new = True  # 是否创建车辆
                        for i in self.cars:
                            if abs(cx - i.c_x) < 30 and abs(cy - i.c_y) < 30:  # 找到这辆车与上一帧中最近的车
                                new = False
                                i.updateCoords(cx, cy)  # 更新车辆位置信息

                                # line_height1-offset<=
                                if i.c_y >= self.line_height1 + self.offset and i.direction == 'down' and i.c_count == False:
                                    i.c_over_time = self.thiscap
                                    i.c_v = self.distance * 3.6 * self.fps / (i.c_over_time - i.c_start_time)
                                    self.occupyTime1 = self.occupyTime1 + i.c_over_time - i.c_start_time
                                    self.count_down += 1
                                    self.listWidget.addItem(
                                        'vehicle-' + str(i.c_id) + '  ' + 'speed:' + '%.2f' % (i.c_v) + 'km/h')
                                    # print('进入下行判断:',add_count_down)

                                    i.c_count = True
                                # 向界面输出速度
                                # <=line_height2+offset
                                if self.line_height2 - self.offset >= i.c_y and i.direction == 'up' and (i.c_count == False):
                                    i.c_over_time = self.thiscap
                                    i.c_v = self.distance * 3.6 * self.fps / (i.c_over_time - i.c_start_time)
                                    self.occupyTime2 = self.occupyTime2 + i.c_over_time - i.c_start_time
                                    self.count_up += 1
                                    self.listWidget.addItem(
                                        'vehicle-' + str(i.c_id) + '  ' + 'speed:' + '%.2f' % (i.c_v) + 'km/h')
                                    # print('进入上行判断:',add_count_up)
                                    i.c_count = True
                                    # 向界面输出速度

                            # if i.c_y>720 or i.c_y<380:
                            #     cars.remove(i) #超过一定范围，删除对象
                        if new == True:  # 符合一定条件，创建对象,and line_height1-offset<cy<line_height2+offset
                            start_time = self.thiscap
                            p = Car(self.pid, cx, cy, 'unknow', False, start_time, 0, 0)
                            if p.c_x < self.left_bound2:
                                p.direction = 'down'
                            else:
                                p.direction = 'up'
                            self.cars.append(p)
                            self.pid += 1
                        # cv2.circle(frame, (cx, cy), 5, (0, 0, 255), -1)
                        # cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 3)

                if null == True:  # 该帧没车，清空cars
                    cars = []


                #窗口显示参数
                self.total_count.setText(str(self.count_down + self.count_up))
                self.volume1.setText('%.0f' % (self.count_down * self.fps * 60 / self.thiscap) + 'veh/min')
                self.volume2.setText('%.0f' % (self.count_up * self.fps * 60 / self.thiscap) + 'veh/min')
                cv2.putText(self.current_image, "Up:" + str(self.count_up), (100, 70), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 255), 5)
                cv2.putText(self.current_image, "Down:" + str(self.count_down), (100, 100), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0),  5)
                self.density1.setText('%.2f' % (self.occupyTime1 * 100 / self.thiscap) + '%')
                self.density2.setText('%.2f' % (self.occupyTime2 * 100 / self.thiscap) + '%')


                # 在Qt界面中显示检测完成画面
                self.show_img(self.current_image)
                self.thiscap += 1
            else:
                # image = cv2.flip(image, 1)  # 左右翻转
                self.current_image = image.copy()

                cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)  # 转成灰度图像
                blur = cv2.GaussianBlur(image, (3, 3), 5, 5)  # 高斯平滑去噪，第七章知识点
                mask = self.bgsubmog.apply(blur)  # 去背景,背景去掉后，留下都是动的物体，比如汽车、刮风动的树、草等，下面是形态学处理去除树和草
                erode = cv2.erode(mask, self.kernel)  # 腐蚀，去掉小的斑块，腐蚀后草就不见了，树有时还能看到
                dilate = cv2.dilate(erode, self.kernel, iterations=3)  # 膨胀3次，还原放大，因为腐蚀后物体变小了，不利于我们计算。
                close = cv2.morphologyEx(dilate, cv2.MORPH_CLOSE, self.kernel, iterations=2)  # 闭操作2次，去掉汽车内部的小块   A

                cnts, h = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)  # 查找轮廓，就是找到每一个移动的汽车了

                cv2.line(self.current_image, (self.left_bound1, self.line_height1), (self.right_bound1, self.line_height1), (255, 255, 255), 2)
                cv2.line(self.current_image, (self.left_bound2, self.line_height2), (self.right_bound2, self.line_height2), (255, 255, 255), 2)
                cv2.line(self.current_image, (0, self.line_height1), (self.frame_width, self.line_height1), (255, 255, 0), 1)
                cv2.line(self.current_image, (0, self.line_height2), (self.frame_width, self.line_height2), (255, 255, 0), 1)

                # 显示检测结果
                cv2.putText(self.current_image, "Up:" + str(self.count_up), (100, 70), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 255), 5)
                cv2.putText(self.current_image, "Down:" + str(self.count_down), (100, 100), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 5)
                # cv2.putText(self.current_image, "max_v:" + str('%.2f' % (self.max_v * 3.6)) + 'km/h', (100, 130), cv2.FONT_HERSHEY_COMPLEX, 1,
                #             (255, 0, 0), 5)

                null = True  # 如果这一帧没有检测到任何车，则将cars置空，减小误差,设置初始变量null设为True
                for cnt in cnts:
                    x, y, w, h = cv2.boundingRect(cnt)
                    cx = int(x + w / 2)
                    cy = int(y + h / 2)

                    if self.line_height2 - 30 < int(y + (h / 2)) < self.line_height1 + 30 and self.left_bound1 < int(
                            x + (w / 2)) < self.right_bound2:
                        if cv2.contourArea(cnt) < 3000 or w < 60 or h < 60:
                            continue
                        null = False  # 有车时不会清空
                        new = True  # 是否创建车辆
                        for i in self.cars:
                            if abs(cx - i.c_x) < 30 and abs(cy - i.c_y) < 30:  # 找到这辆车与上一帧中最近的车
                                # cv.putText(frame, 'cid:' + str(i.c_id), (x, y-10), cv.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 2)
                                # cv.putText(frame, "now_v:" + str('%.4f' % (i.c_v)) + 'm/s', (x, y-10),
                                #            cv.FONT_HERSHEY_COMPLEX, 1,
                                #            (255, 0, 0), 2)
                                new = False
                                i.updateCoords(cx, cy)  # 更新车辆位置信息
                                cv2.putText(self.current_image, "vehicle-" + str(i.c_id), (int(x + w / 2), int(y - 5)),
                                            cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)

                                # line_height1-offset<=
                                if i.c_y >= self.line_height1 + self.offset and i.direction == 'down' and i.c_count == False:
                                    i.c_over_time = self.thiscap
                                    i.c_v = self.distance * 3.6 * self.fps / (i.c_over_time - i.c_start_time)
                                    self.occupyTime1 = self.occupyTime1 + i.c_over_time - i.c_start_time
                                    self.count_down += 1
                                    self.total_count.setText(str(self.count_down+self.count_up))
                                    # 下行车流量
                                    self.volume1.setText('%.0f' % (self.count_down * self.fps * 60 / self.thiscap)+'veh/min')
                                    self.listWidget.addItem('vehicle-' + str(i.c_id) + '  ' + 'speed:' + '%.2f' %(i.c_v)+'km/h')
                                    i.c_count = True

                                    # 向界面输出速度

                                # <=line_height2+offset
                                if self.line_height2 - self.offset >= i.c_y and i.direction == 'up' and (i.c_count == False):
                                    i.c_over_time = self.thiscap
                                    i.c_v = self.distance * 3.6 * self.fps / (i.c_over_time - i.c_start_time)
                                    self.occupyTime2 = self.occupyTime2 + i.c_over_time - i.c_start_time
                                    self.count_up += 1
                                    self.total_count.setText(str(self.count_down + self.count_up))
                                    # 上行车流量 '%.2f' % (carnum*24.99*60/time) + 'veh/min'
                                    self.volume2.setText('%.0f' % (self.count_up * self.fps * 60 / self.thiscap) + 'veh/min')
                                    self.listWidget.addItem('vehicle-'+str(i.c_id)+'  '+'speed:'+'%.2f' %(i.c_v)+'km/h')
                                    i.c_count = True

                                    # 向界面输出速度

                            # if i.c_y>720 or i.c_y<380:
                            #     cars.remove(i) #超过一定范围，删除对象

                        if new == True:  # 符合一定条件，创建对象,and line_height1-offset<cy<line_height2+offset
                            start_time = self.thiscap
                            p = Car(self.pid, cx, cy, 'unknow', False, start_time, 0, 0)
                            if p.c_x < self.left_bound2:
                                p.direction = 'down'
                            else:
                                p.direction = 'up'
                            self.cars.append(p)
                            self.pid += 1

                        cv2.circle(self.current_image, (cx, cy), 5, (0, 0, 255), -1)
                        cv2.rectangle(self.current_image, (x, y), (x + w, y + h), (0, 0, 255), 3)

                if null == True:  # 该帧没车，清空cars
                    self.cars = []
                    self.density1.setText('%.2f' %(self.occupyTime1 * 100/ self.thiscap)+'%')
                    self.density2.setText('%.2f' % (self.occupyTime2 * 100 / self.thiscap) + '%')
                # time_start = time.time()  # 计时
                # # 使用模型预测
                # self.dets, self.boxes, self.indexIDs, self.cls_IDs = self.detector_model.run(image)
                # time_end = time.time()
                # try:
                #     if len(self.boxes) > 0:  # 追踪到目标
                #         self.sign_up(image, 1)
                #         # 更新检测目标数目
                #         QtWidgets.QApplication.processEvents()
                #     else:
                #         # 更新检测目标数目
                #         a = 1
                #
                #     # 是否检测到目标
                #     if len(self.dets) == 0:
                #         font = QtGui.QFont()
                #         font.setPointSize(18)
                # except:
                #     print("[INFO] 目标消失，请重新选择目标选项！")

                # 在Qt界面中显示检测完成画面
                self.show_img(self.current_image)
                self.thiscap += 1
        else:
            self.timer_video.stop()

    def button_open_video_click(self):
        self.type = 2
        if self.timer_camera.isActive():
            self.timer_camera.stop()
            # 清空参数显示
            self.listWidget.clear()
            self.total_count.clear()
            self.volume1.clear()
            self.volume2.clear()
            self.density1.clear()
            self.density2.clear()

        if not self.timer_video.isActive():  # 检查定时状态
            # 弹出文件选择框选择视频文件
            fileName_choose, filetype = QFileDialog.getOpenFileName(self.centralwidget, "选取视频文件",
                                                                    self.video_path,  # 起始路径
                                                                    "视频(*.mp4;*.avi)")  # 文件类型
            self.video_path = fileName_choose

            if fileName_choose != '':
                self.flag_timer = "video"
                ## 打开视频
                self.textEdit_video.setText(fileName_choose + '文件已选中')
                self.textEdit_video.setStyleSheet(self.textlineSty)
                self.label_display.setText('正在启动识别系统...\n\nleading')
                QtWidgets.QApplication.processEvents()

                try:  # 初始化视频流
                    self.cap_video = cv2.VideoCapture(fileName_choose)
                    self.fps = round(self.cap_video.get(cv2.CAP_PROP_FPS))
                    self.frame_height = int(self.cap_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
                    self.frame_width = int(self.cap_video.get(cv2.CAP_PROP_FRAME_WIDTH))

                    self.thiscap = 1
                    self.occupyTime1 = 0
                    self.occupyTime2 = 0

                    self.count_up = 0
                    self.count_down = 0
                    self.cars = []
                    self.pid = 1
                    self.distance = 8

                    self.line_height1 = 570  # 红计数线位置
                    self.line_height2 = 470  # 红计数线位置
                    self.offset = 5  # 计数线上下的偏移量
                    self.left_bound1 = 0
                    self.right_bound1 = 560
                    self.left_bound2 = 660
                    self.right_bound2 = 1000

                    self.bgsubmog = cv2.bgsegm.createBackgroundSubtractorMOG()  # 视频去背景，第二十一章知识点
                    self.kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))  # 设置形态学处理的kernel，5x5的矩形即可，第八章知识点
                except:
                    print("[INFO] could not determine # of frames in video")
                # 准备运行识别程序
                self.textEdit_pic.setText('文件未选中')
                self.textEdit_pic.setStyleSheet(self.textlineSty)
                QtWidgets.QApplication.processEvents()
                self.textEdit_camera.setText('实时摄像未启动')
                self.textEdit_camera.setStyleSheet(self.textlineSty)
                # self.textEdit_video.setText(fileName_choose + '文件已选中')
                # self.textEdit_video.setStyleSheet("background-color: transparent;\n"
                #                                   "border-color: rgb(0, 170, 255);\n"
                #                                   "color: rgb(0, 170, 255);\n"
                #                                   "font: regular 12pt \"华为仿宋\";")
                # self.label_display.setText('正在启动识别系统...\n\nleading')

                # 新建对象
                # self.pts = [deque(maxlen=30) for _ in range(9999)]
                # self.detector_model = Detector(model_path=self.model_path)
                # KalmanBoxTracker.count = 0

                self.restore()
                # 打开定时器
                self.timer_video.start(1000/self.fps)

            else:
                # 选择取消，恢复界面状态
                self.flag_timer = ""
                self.textEdit_pic.setText('文件未选中')
                self.textEdit_pic.setStyleSheet(self.textlineSty)
                self.textEdit_camera.setText('实时摄像已关闭')
                self.textEdit_camera.setStyleSheet(self.textlineSty)
                self.textEdit_video.setText('实时视频未选中')
                self.textEdit_video.setStyleSheet(self.textlineSty)
                self.label_display.clear()  # 清除画面
                self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")


        else:
            # 定时器未开启，界面回复初始状态
            self.flag_timer = ""
            self.timer_video.stop()
            self.cap_video.release()
            self.label_display.clear()
            self.textEdit_pic.setText('文件未选中')
            self.textEdit_pic.setStyleSheet(self.textlineSty)
            self.textEdit_camera.setText('实时摄像已关闭')
            self.textEdit_camera.setStyleSheet(self.textlineSty)
            self.textEdit_video.setText('实时视频已关闭')
            self.textEdit_video.setStyleSheet(self.textlineSty)

            self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")
            self.restore()

    def show_camera(self):
        # 定时器槽函数，每隔一段时间执行
        flag, image = self.cap.read()  # 获取画面
        if flag:
            self.current_image = image.copy()

            time_start = time.time()  # 计时
            # 使用模型预测
            self.dets, self.boxes, self.indexIDs, self.cls_IDs = self.detector_model.run(image)
            time_end = time.time()
            try:
                if len(self.boxes) > 0:  # 追踪到目标
                    self.sign_up(image, 1)
                    # 更新检测目标数目
                    QtWidgets.QApplication.processEvents()
                else:
                    # 更新检测目标数目
                    a = 1

                # 是否检测到目标
                if len(self.dets) == 0:
                    font = QtGui.QFont()
                    font.setPointSize(18)
            except:
                print("[INFO] 目标消失，请重新选择目标选项！")

            # 在Qt界面中显示检测完成画面
            self.show_img(image)

        else:
            self.timer_video.stop()



    def select_obj(self):
        QtWidgets.QApplication.processEvents()
        if self.flag_timer == "video":
            # 打开定时器
            self.timer_video.start(1000/self.fps)
        elif self.flag_timer == "camera":
            self.timer_camera.start(30)

        image = self.current_image.copy()
        if len(self.boxes) > 0:
            self.sign_up(image, 0)
        # 在Qt界面中显示检测完成画面
        self.show_img(image)

    def cv_imread(self, filePath):
        # 读取图片
        # cv_img = cv2.imread(filePath)
        cv_img = cv2.imdecode(np.fromfile(filePath, dtype=np.uint8), -1)
        ## imdecode读取的是rgb，如果后续需要opencv处理的话，需要转换成bgr，转换后图片颜色会变化
        ## cv_img=cv2.cvtColor(cv_img,cv2.COLOR_RGB2BGR)
        if cv_img.shape[2] > 3:
            cv_img = cv_img[:, :, :3]
        return cv_img

    def save_file(self):
        if self.detected_image is not None:
            now_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
            cv2.imwrite('./pic_' + str(now_time) + '.png', self.detected_image)
            QMessageBox.about(self.centralwidget, "保存文件", "<font size='18pt' color='black'> Successed!<br />文件已保存！</font>")

        else:
            QMessageBox.about(self.centralwidget, "保存文件", "<font size='18pt' color='black'> saving...<br />Failed!<br />请先选择检测操作！</font>")

    def setting(self):
        # "保存位置为当前文件夹路径\n更多设置参数待更新\n智能运输检测技术综合设计小组"
        QMessageBox.about(self.centralwidget, "图片默认保存位置","<font size='18pt' color='black'>保存位置为当前文件夹路径"
                                                         " <br />更多设置参数待更新"
                                                         " <br />智能运输检测技术综合设计小组</font>")

    def disp_version(self):
        QMessageBox.about(self.centralwidget, "版本信息", "<font size='18pt' color='black'>车辆检测与交通流参数计算v1.0<br />智能运输检测技术综合设计小组</font>")

    def disp_mail(self):
        QMessageBox.about(self.centralwidget, "联系作者", "<font size='18pt' color='black'>作者邮箱：<br />19221342@bjtu.edu.cn</font>")

    def restore(self):
        font = QtGui.QFont()
        font.setPointSize(18)
        # 选择图片文件
        if self.type == 1:
            self.textEdit_camera.setText('实时摄像已关闭')
            self.textEdit_camera.setStyleSheet(self.textlineSty)
            self.textEdit_video.setText('实时视频已关闭')
            self.textEdit_video.setStyleSheet(self.textlineSty)
            self.label_display.clear()
            self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")
        # 选择视频文件或摄像头
        if self.type == 2 or self.type == 3:
            QtWidgets.QApplication.processEvents()
        if self.type == 4:
            self.textEdit_pic.setText('文件未选中')
            self.textEdit_pic.setStyleSheet(self.textlineSty)
            self.textEdit_camera.setText('实时摄像已关闭')
            self.textEdit_camera.setStyleSheet(self.textlineSty)
            self.textEdit_video.setText('实时视频已关闭')
            self.textEdit_video.setStyleSheet(self.textlineSty)
            self.label_display.clear()
            self.label_display.setStyleSheet("border-image: url(:/newPrefix/images_test/ini-image.png);")

    def show_img(self, image):
        image = cv2.resize(image, (1152, 648))  # 设定图像尺寸为显示界面大小
        show = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        showImage = QtGui.QImage(show.data, show.shape[1], show.shape[0], QtGui.QImage.Format_RGB888)
        self.label_display.setPixmap(QtGui.QPixmap.fromImage(showImage))

    def sign_up(self, image, type):
        for i, box in enumerate(self.boxes):  # 遍历所有标记框
            (x, y) = (int(box[0]), int(box[1]))
            (w, h) = (int(box[2]), int(box[3]))
            center = (int(((box[0]) + (box[2])) / 2), int(((box[1]) + (box[3])) / 2))
            self.pts[self.indexIDs[i]].append(center)
        color = [int(c) for c in self.COLORS[self.indexIDs[i] % len(self.COLORS)]]
        cv2.rectangle(image, (x, y), (w, h), color, 4)

        thickness = 5

        if self.radioButton_countting.isChecked():
            # 显示某个对象标记框的中心
            cv2.circle(image, center, 1, color, thickness)

            # 显示运动轨迹
            for j in range(1, len(self.pts[self.indexIDs[i]])):
                if self.pts[self.indexIDs[i]][j - 1] is None or self.pts[self.indexIDs[i]][j] is None:
                    continue
                thickness = int(np.sqrt(64 / float(j + 1)) * 2)
                cv2.line(image, (self.pts[self.indexIDs[i]][j - 1]), (self.pts[self.indexIDs[i]][j]),
                         color,
                         thickness)

        # 标记跟踪到的目标和数目
        if self.radioButton_detection.isChecked():
            text = "{}-{}".format(self.LABELS[int(self.cls_IDs[i])],
                                  round(self.dets[len(self.boxes) - i - 1][4], 2))
        else:
            text = "{}-{}".format(self.LABELS[int(self.cls_IDs[i])], self.indexIDs[i])
        cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, color, 3)

        if type == 1:
            # 更新界面

            if len(self.LABELS[int(self.cls_IDs[i])]) > 7:
                font = QtGui.QFont()
                font.setPointSize(12)
            else:
                font = QtGui.QFont()
                font.setPointSize(18)
